<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p>1</p>
    <p>2</p>
    <p>3</p>
</body>
<script>
    // 1.声明数组
    // 2.获取元素
    // 3. 设置随机数
    // 4.拿到随机数的元素
    // 5.给元素修改文本内容
    const all = document.querySelectorAll('p');
    const arr = ['刘德华', '张学友', '黎明', '郭富城'];
    for (let i = 0; i <= arr.length; i++) {
        const random = Math.floor(Math.random() * arr.length);
        all[i].innerHTML = arr[random];
        let de = arr.indexOf(arr[random]);
        arr.splice(de, 1);
    }

</script>

</html>